#ifndef CONCREATEITERATER_H
#define CONCREATEITERATER_H

#include "Iterator.h"
#include "Aggregate.h"

template <class T>
class ConcreateIterater : public Iterator<T>
{
    public:
        ConcreateIterater(Aggregate<T> * aggregate);
        virtual ~ConcreateIterater();

        void first();

        void next();

        bool isDone();

        T getCurrentItem();

    protected:

    private:
        Aggregate<T> * aggregate;

        int nIndex;

};

template<class T>
ConcreateIterater<T>::ConcreateIterater(Aggregate<T> * aggregate): aggregate(aggregate), nIndex(0)
{

}

template<class T>
void ConcreateIterater<T>::first()
{
    this->nIndex = 0;
}

template<class T>
void ConcreateIterater<T>::next()
{
    if (this->nIndex < this->aggregate->getSize()) {
        this->nIndex ++;
    }
}

template<class T>
bool ConcreateIterater<T>::isDone()
{
   return this->nIndex > this->aggregate->getSize() -1;
}

template<class T>
T ConcreateIterater<T>::getCurrentItem()
{
    return this->aggregate->getItem(this->nIndex);
}

template<class T>
ConcreateIterater<T>::~ConcreateIterater()
{
    this->nIndex = 0;

    delete this->aggregate;
}

#endif // CONCREATEITERATER_H
